
function addTC() {
	var te_name = document.getElementById("te_name");
	var te_summary = document.getElementById("te_summary");
	//var te_owner = document.getElementById("te_owner");
	var te_description = document.getElementById("te_description");
	var te_script = document.getElementById("te_script");
	TC = new Object();
	TC['te_name'] = te_name.value;
	TC['te_summary'] = te_summary.value;
	//TC['te_owner'] = te_owner.value;
	TC['te_description'] = te_description.value;
	TC['te_script'] = te_script.value;
	dump(TC);
	fillTCrun(TC);
}

function setParent( tc_parent, parent_name, type, state) {
	var rd = document.getElementById("te_parent_name");
	var tele = document.getElementById("te_type");
	tele.value = type;
	if (type == "fl")
		type = "Folder";
	else
		type = "Test Case";
	if (state == 0) //new
		state = "Create new "+ type+ " parent is "+ parent_name;
	else		// edit
		state = "Editing "+type+" "+parent_name ;
	rd.value = state;
	rd = document.getElementById("te_parent_num");
	rd.value = tc_parent;
}

function cancelTCedit() {
	var rd = document.getElementById("te_name");
	rd.value="";
	rd = document.getElementById("te_summary");
    rd.value="";
	//rd = document.getElementById("te_owner");
    //rd.value="";
    rd = document.getElementById("te_description");
    rd.value="";
	rd = document.getElementById("te_script");
    rd.value="";
    rd = document.getElementById("te_stepnum");
    rd.value="";
    rd = document.getElementById("te_stepdesc");
    rd.value="";
    td = document.getElementById("test_deck");
    td.setAttribute("selectedIndex", 0);
	enableAllEdit();
}

function clearAllEdit(){
    var rd = document.getElementById("te_name");
	rd.disabled=true;
    rd.value="";
	rd = document.getElementById("te_summary");
	rd.disabled=true;
    rd.value="";
	rd=document.getElementById("te_description");
	rd.disabled=true;
	rd.value="";
	rd=document.getElementById("te_script");
	rd.disabled=true;
    rd.value="";
}

function enableAllEdit(){
    var rd = document.getElementById("te_name");
	rd.disabled = false;
    rd.value="";
    rd = document.getElementById("te_summary");
	rd.disabled=false;
    rd.value="";
    //rd = document.getElementById("te_owner");
    //rd.value="";
    rd=document.getElementById("te_description");
    rd.disabled=false;
    rd.value="";
    rd=document.getElementById("te_script");
    rd.disabled=false;
    rd.value="";
}

function stepEdit(){

	var step_tree = document.getElementById("step_tree");
	var step_view = step_tree.view;
	var index = step_tree.currentIndex;
	var ida = step_tree.view.getCellValue(index, step_tree.columns.getColumnAt(0));
	var idb = step_tree.view.getCellValue(index, step_tree.columns.getColumnAt(1));
	var rd = document.getElementById("te_stepnum");
	rd.value=ida;
	var rd = document.getElementById("te_stepdesc");
	rd.value=idb;	
}

function clearMyName(){
	var rd = document.getElementById("te_dirtc_name");
	rd.value="";
}

function fillTCedit( tc){

	//var rd = document.getElementById("te_parent");
	//rd.value = tc.parent_name;
	var rd = document.getElementById("te_parent_num");
	rd.value = tc.tc_parent;
	rd = document.getElementById("te_name");
        rd.value = tc.tc_name;
	rd = document.getElementById("te_summary");
	rd.value = tc.tc_summary; 
	rd = document.getElementById("te_description");
	rd.value = tc.tc_desc;


}

function newTCedit() {
	var rd = document.getElementById("te_parent_num");
	tc = {}
	tc.tc_parent = rd.value;
	rd = document.getElementById("te_name");
	tc.tc_name = rd.value;
	rd = document.getElementById("te_summary");
	tc.tc_summary = rd.value;
	rd = document.getElementById("te_description");
	tc.tc_desc = rd.value;
	rd = document.getElementById("te_testcase");
	if (rd.getAttribute("selected"))
		tc.tc_type = "tc"
	else
		tc.tc_type = "fl"
	cmd = {}
    cmd['type'] = "cmd";
    cmd['cmd'] = "newTC";
    cmd['tc'] = tc;
    listtc_conn = new tcListener( JSON.stringify(cmd));

}

function accessTC( tc){

	var rd = document.getElementById("te_name");
	rd.value=tc.tc_name;

}

function commit(){
	var tc = new Object();
	tc['tc_parent'] = document.getElementById("te_parent_num").value;
	if (tc['tc_parent'] == -1)
		return;
	tc['tc_name'] = document.getElementById("te_name").value;
	tc['tc_summary'] = document.getElementById("te_summary").value;
	tc['tc_desc'] = document.getElementById("te_description").value;
	tc['tc_type'] = document.getElementById("te_type").value;
	var cmd = new Object();
    cmd['type'] = "cmd";
    cmd['cmd'] = "newTC";
    cmd['tc'] = tc;
    listtc_conn = new tcListener( JSON.stringify(cmd));
}

function testmenoW(){

/*this is a test*/

	if (document.getElementById("te_folder").selected == "true") {
                var rd = document.getElementById("te_parent");
		rd.value = "I'm a FOLDER!";
        }
        else if (documnent.getElementById("te_testcase").selected == "true") {
		var rd = document.getElementById("te_parent");
		rd.value = "I'm a TESTCASE!";
        }
        else {
/* If edit do something important here!*/
		var rd = document.getElementById("te_parent");
		rd.value = "I'm a HERMAPHRODITE!";

        }
}



